/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package GameRules.impl;

import BoardGame.Field;

import BoardGame.impl.FigureImpl;

import GameRules.GameRulesPackage;
import GameRules.NW_KnightWhite;

import de.upb.tools.sdm.*;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>NW Knight White</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * </p>
 *
 * @generated
 */
public class NW_KnightWhiteImpl extends FigureImpl implements NW_KnightWhite {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected NW_KnightWhiteImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GameRulesPackage.Literals.NW_KNIGHT_WHITE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void moveTo(Field field) {
		boolean fujaba__Success = false;
		Field field12 = null;
		Field field11 = null;
		Field field00 = null;
		Field currentField = null;
		Field field01 = null;

		// story pattern 
		try {
			fujaba__Success = false;

			// check object field is really bound
			JavaSDM.ensure(field != null);
			// bind object
			field01 = field.getNeighbourWest();

			// check object field01 is really bound
			JavaSDM.ensure(field01 != null);

			// check isomorphic binding between objects field01 and field
			JavaSDM.ensure(!field01.equals(field));

			// bind object
			currentField = this.getField();

			// check object currentField is really bound
			JavaSDM.ensure(currentField != null);

			// check isomorphic binding between objects field01 and currentField
			JavaSDM.ensure(!field01.equals(currentField));

			// check isomorphic binding between objects field and currentField
			JavaSDM.ensure(!field.equals(currentField));

			// bind object
			field00 = currentField.getNeighbourNorth();

			// check object field00 is really bound
			JavaSDM.ensure(field00 != null);

			// check isomorphic binding between objects field00 and currentField
			JavaSDM.ensure(!field00.equals(currentField));

			// check isomorphic binding between objects field01 and field00
			JavaSDM.ensure(!field01.equals(field00));

			// check isomorphic binding between objects field00 and field
			JavaSDM.ensure(!field00.equals(field));

			// check link NeighbourWest from field01 to field00
			JavaSDM.ensure(field00.equals(field01.getNeighbourWest()));

			// bind object
			field11 = currentField.getNeighbourEast();

			// check object field11 is really bound
			JavaSDM.ensure(field11 != null);

			// check isomorphic binding between objects field11 and currentField
			JavaSDM.ensure(!field11.equals(currentField));

			// check isomorphic binding between objects field11 and field00
			JavaSDM.ensure(!field11.equals(field00));

			// check isomorphic binding between objects field11 and field01
			JavaSDM.ensure(!field11.equals(field01));

			// check isomorphic binding between objects field11 and field
			JavaSDM.ensure(!field11.equals(field));

			// bind object
			field12 = field11.getNeighbourEast();

			// check object field12 is really bound
			JavaSDM.ensure(field12 != null);

			// check isomorphic binding between objects field12 and currentField
			JavaSDM.ensure(!field12.equals(currentField));

			// check isomorphic binding between objects field12 and field00
			JavaSDM.ensure(!field12.equals(field00));

			// check isomorphic binding between objects field12 and field01
			JavaSDM.ensure(!field12.equals(field01));

			// check isomorphic binding between objects field12 and field11
			JavaSDM.ensure(!field12.equals(field11));

			// check isomorphic binding between objects field12 and field
			JavaSDM.ensure(!field12.equals(field));

			// destroy link
			currentField.setFigure(null);
			// create link
			field.setFigure(this);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		if (fujaba__Success) {
			return;

		} else {
			return;

		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments)
			throws InvocationTargetException {
		switch (operationID) {
		case GameRulesPackage.NW_KNIGHT_WHITE___MOVE_TO__FIELD:
			moveTo((Field) arguments.get(0));
			return null;
		}
		return super.eInvoke(operationID, arguments);
	}

} //NW_KnightWhiteImpl
